package org.cqut.system.work_content.controller;

import org.cqut.framework.web.response.ResultInfo;
import org.cqut.framework.web.response.Status;
import org.cqut.system.work_content.domain.WorkContent;
import org.cqut.system.work_content.service.WorkContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author XiAoXu
 * @date 2021/11/13 17:09
 * @description
 */
@RestController
@RequestMapping("/workContent")
public class WorkContentController {
    @Autowired
    private WorkContentService workContentService;

    @RequestMapping(path = "/list/{courseId}", method = RequestMethod.GET)
    public ResultInfo queryWorkList(@PathVariable("courseId") String courseId) {
        List<WorkContent> workContent = workContentService.workList(courseId);
        if (workContent != null) {
            return new ResultInfo(Status.QUERY_DETAILS_SUCCESS.code, Status.QUERY_DETAILS_SUCCESS.message, workContent);
        } else {
            return new ResultInfo(Status.QUERY_DETAILS_ERROR.code, Status.QUERY_DETAILS_ERROR.message);
        }
    }

    @RequestMapping(method = RequestMethod.POST,path = "/del/{contentId}")
    public ResultInfo deleteWork(@PathVariable String contentId){
        boolean flag = workContentService.removeById(contentId);
        if (flag) {
            return new ResultInfo(Status.SUCCESS.code, Status.SUCCESS.message);
        } else {
            return new ResultInfo(Status.WARN.code, Status.WARN.message);
        }
    }

}
